#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    int lengthOfLastWord(string s) {
        int posback = s.size() - 1;
        while (posback >= 0 && s[posback] == ' ') {
            posback--;
        }
        int ans = 0;
        while (posback >= 0 && s[posback] != ' ') {
            ans++; posback--;
        }
        return ans;
    }
};